home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 111_01 / senter.c < prev    next >
Text File  |  1985-08-19  |  5KB  |  242 lines

  1. /*
  2. HEADER:        ;
  3. TITLE:        Screen entry;
  4. VERSION:    1.0;
  5.  
  6. DESCRIPTION:    "General screen oriented input/output module.
  7.         This is a component of the diskette sector editor,
  8.         SE.C, but may be useful in other C programs.";
  9.  
  10. KEYWORDS:    Editor, screen;
  11. SYSTEM:        CP/M-80, V2.2;
  12. FILENAME:    SENTER.C;
  13. SEE-ALSO:    SE.C, SE.DOC;
  14. AUTHORS:    Jan Larsson;
  15. COMPILERS:    BDS C, v1.43 and 1.5a;
  16. */
  17. /***********************************************************
  18.  
  19. Version 1.0, 1981:
  20.     Jan Larsson, Kosterv. 12, S-181 35  Lidingo, SWEDEN
  21.  
  22. ************************************************************/
  23.  
  24. #include <bdscio.h>
  25.  
  26. #define LCHR '_'
  27. #define ECHR ' '
  28. #define BS 0x08
  29. #define ESC 0x1B
  30.  
  31. /* Raw character output routine */
  32.  
  33. co( c )
  34. char c ;
  35. {
  36.     bdos( 6, c );
  37.     if(c == 0x0a)bdos( 6, 0x0d );
  38. }
  39.  
  40.  
  41. /* Raw character input routine */
  42.  
  43. ci(){
  44.     char c ;
  45.  
  46.     while((c = bdos( 6, 0xff )) == 0);
  47.     if(c == 0x03)stop();
  48.     return( c );
  49. }
  50.  
  51.  
  52. /* tplot plots a text at the cursor adress given */
  53.  
  54. tplot( x, y, text )
  55. char x, y, *text ;
  56. {
  57.     gotoxy( x, y );
  58.     pl( text );
  59. }
  60.  
  61.  
  62. /* print a text at the current position */
  63.  
  64. pl( text )
  65. char *text ;
  66. {
  67.     while(*text != '\0') co( *text++ );
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74. bit( c, number )
  75. char c, number ;
  76. {
  77.     return(((c >> number) & 0x01));
  78. }
  79.  
  80.  
  81.  
  82.  
  83. /*
  84.     ENTER() is a general input routine for CRT terminals with cursor
  85.     adressing. It is called with six parameters (described below) and
  86.     returns TRUE if any characters were input, else FALSE is returned.
  87.     A special case occurs if the ESCAPE key was depressed, if so the
  88.     function will exit immediately and return ESCAPE.
  89.  
  90.     Call parameters:
  91.         
  92.         retval = enter( x, y, text, len, inbuf, mode );
  93.  
  94.         x     is the column on the screen
  95.  
  96.         y    is the row on the screen (0 - 23)
  97.  
  98.         text    a pointer to the text printed before input
  99.  
  100.         len    is the maximum number of bytes allowed as input
  101.  
  102.         inbuf   a pointer to the buffer where input will be copied
  103.  
  104.         mode    a byte which controls the functioning of enter(),
  105.                 bit 0 :  only numerical input accepted
  106.                 bit 1 :  upper case conversion
  107.                 bit 2 :  wait for input
  108.                 bit 3 :  print contents of inbuf first
  109.                 bit 4 :  print contents of text
  110.                 bit 5 :  clear inbuf before inbuf, after bit 3
  111.                 bit 6 :  print 'mark' line on screen
  112.                 bit 7 :  not implemented yet
  113.  
  114.             
  115.             (c) 1981 Jan Larsson, Occam Software
  116. */
  117.  
  118.  
  119. char enter( x, y, text, len, inbuf, mode )
  120. char x, y, *text, len, *inbuf, mode ;
  121. {
  122.     int z ;
  123.     char buf[255], x2, y2, numerical, upper, print, input, ledtext ;
  124.     char nolla, wrap, n, *p, c, points ;
  125.  
  126.     numerical = bit( mode, 0 );
  127.     upper     = bit( mode, 1 );
  128.     input     = bit( mode, 2 );
  129.     print     = bit( mode, 3 );
  130.     ledtext   = bit( mode, 4 );
  131.     nolla      = bit( mode, 5 );
  132.     points    = bit( mode, 6 );
  133.  
  134.     y2 = y ; x2 = x + strlen( text );
  135.  
  136.     if( ledtext )tplot( x, y, text );
  137.  
  138.     if( print ){
  139.         tplot( x2, y2, inbuf );
  140.         if( points ){
  141.             n = len - strlen( inbuf );
  142.             while(n-- > 0)co(LCHR);
  143.             co( ECHR );
  144.             }
  145.         }
  146.     else if( points ){
  147.         gotoxy( x2, y2 );
  148.         n = len ;
  149.         while(n-- > 0)co( LCHR );
  150.         co( ECHR );
  151.         }
  152.  
  153.     if( nolla )*inbuf = '\0' ;
  154.  
  155.     if( ! input )return( FALSE );
  156.  
  157.     gotoxy( x2, y2 ); bell() ; c = '\0' ;
  158.     p = buf ; z = 0 ; wrap = FALSE ;
  159.  
  160.     while( ! eoi( c ) ){
  161.         if( numerical )while( nodigit((c = ci())));
  162.         else while( unacceptable((c = ci())));
  163.         if(c == ESC)return( ESC );
  164.         if((p - buf) >= len && c != BS && ! eoi( c )){
  165.              wrap = TRUE ; gotoxy( x2, y2 ); }
  166.         if(c == BS && p == buf)bell();
  167.         else if(c == BS){
  168.             z-- ; p-- ;
  169.             co( BS ) ; co( LCHR ) ; co( BS ) ;
  170.             }
  171.         else if( ! eoi( c ) ){
  172.             c = upper ? toupper( c ) : c ;
  173.             if( wrap ){
  174.                 wrap = FALSE ;
  175.                 n = len ;
  176.                 bell() ;
  177.                 while(n-- > 0)co( LCHR );
  178.                 co( ECHR );
  179.                 gotoxy( x2, y2 );
  180.                 z = 0 ; p = buf ;
  181.                 }
  182.             *p++ = c ;
  183.             z++ ;
  184.             co( c );
  185.             }
  186.         }
  187.     *p = '\0' ;
  188.     p-- ;
  189.     if(z == 0)return( FALSE );
  190.     while(*p == ' '){ co( BS ) ; co( LCHR ) ; co( BS ); p-- ; }
  191.     p++ ;
  192.     *p = '\0' ;
  193.     strcpy( inbuf, buf );
  194.     return( TRUE );
  195. }
  196.  
  197.  
  198.  
  199. bell(){ co( 7 ); }
  200.  
  201.  
  202. /* eoi() returns TRUE when a terminating character has been typed */
  203.  
  204. char eoi( c )
  205. char c ;
  206. {
  207.     switch ( c ) {
  208.  
  209.         case 0x0d :
  210.         case 0x0a : return( TRUE ) ; break ;
  211.  
  212.         default   : return( FALSE ) ;
  213.         }
  214. }
  215.  
  216.  
  217.  
  218.  
  219. /* nodigit() returns true if the character is not a digit */
  220.  
  221. char nodigit( c )
  222. char c ;
  223. {
  224.     if((c >= '0' && c <= '9') || c == BS || c == ESC || eoi( c ))
  225.                             return( FALSE );
  226.     else return( TRUE );
  227. }
  228.  
  229.  
  230. /* unacceptable() returns TRUE if c is control character */
  231.  
  232. char unacceptable( c )
  233. char c ;
  234. {
  235.     if((c >= ' ' && c < 0x7f) || eoi( c ) || c == BS || c == ESC)
  236.                             return( FALSE );
  237.     else return( TRUE );
  238. }
  239.  
  240.  
  241.  
  242.